package com.expressage.controller;

import com.expressage.po.Salary;
import com.expressage.service.SalaryService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
public class SalaryController {
    @Autowired
    SalaryService salaryService;
    Logger logger = Logger.getLogger(SalaryController.class);

    @RequestMapping("jspafter/salarylist")
    public String findAll(Model model){
        logger.info("进入查询薪资的控制器");
        List<Salary> list = salaryService.findAll();
        model.addAttribute("salarylist",list);
        return  "jspafter/salarylist";
    }
    @RequestMapping("jspafter/salarylistone")
    public String findByid(int salaryid,Model model){
        Salary salary =   salaryService.findByid(salaryid);
        model.addAttribute(salary);
        return "jspafter/salarylistone";
    }
    @RequestMapping("jspafter/toaddsalary")
     public String add(){
        logger.info("去添加薪资信息");
        return "jspafter/addsalary";
    }

    @RequestMapping("jspafter/addsalary")
    public String add(Salary salary) {
        logger.info("进入查询薪资的控制器");
        boolean flag =salaryService.add(salary);
        logger.info(flag);
        return "redirect:salarylist.action";
    }

   @RequestMapping("jspafter/deletesalary")
    public String delete(int[] array){
        logger.info("进入删除薪资信的控制器");
       if(array.length>0){
           boolean falg = salaryService.delete(array);
           logger.info(falg?true:false);
       }
        return "redirect:salarylist.action";
   }

   @RequestMapping("jspafter/toupdatesalary")
    public String update(int salaryid,Model model){
      Salary salary =  salaryService.findByid(salaryid);
       model.addAttribute(salary);
       logger.info("去进入修改薪资的控制器");
        return "jspafter/updatesalary";
   }
   @RequestMapping("jspafter/updatesalary")
    public String update(Salary salary){
        logger.info("进入修改薪资的控制器");
       boolean flag =  salaryService.update(salary);
       return "redirect:salarylist.action";
   }
}
